package com.example.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.R;
import com.example.pojo.User;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("findPage")
    public List<User> findPage(@RequestParam(required = true,defaultValue = "1")Integer pageIndex){
           return userService.findAll();
    }

    @RequestMapping("/del")
    public String del(@RequestParam("id") Long id){
         userService.del(id);
         return "删除成功";
    }

    @RequestMapping("/add")
    public String add(@RequestBody User user){
         userService.add(user);
         return "添加成功";
    }

    @RequestMapping("/update")
    public String update(@RequestBody User user){
         userService.update(user);
         return "修改成功";
    }
    @GetMapping("{id}")
    public User findById(@PathVariable Long id){
        return userService.findById(id);
    }
}
